package com.pj.point;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.snackbar.Snackbar;

public class Register extends AppCompatActivity {

    EditText account;
    EditText password;
    Button register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ActionBar bar = getSupportActionBar();
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setTitle("注册用户");
        account = findViewById(R.id.r_account);
        password = findViewById(R.id.r_password);
        register = findViewById(R.id.bt_register);
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String act = account.getText().toString();
                String pwd = password.getText().toString();
                if (act.equals("")||pwd.equals(""))
                {
                    Snackbar.make(v,"您犯了一个非常愚蠢的错误，让我们来看看它是什么",Snackbar.LENGTH_SHORT)
                            .setAction("查看", new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Toast.makeText(Register.this, "脑子有包么？用户名和密码都不晓得写", Toast.LENGTH_LONG).show();
                                }
                            }).show();
                }
                else
                {
                    SharedPreferences.Editor user = getSharedPreferences("data", MODE_PRIVATE).edit();
                    user.putString("username",act);
                    user.putString("password",pwd);
                    user.apply();
                    Toast.makeText(Register.this, "注册成功", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        });

    }


    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        finish();
        return super.onOptionsItemSelected(item);
    }
}